import {
  initManuallyRender
} from '../../static/CIM/BQGIS-manuallyRender'


/**
 * 
 * @returns 合并 默认属性及自定义属性
 */
export function mapOptions() {
  let options = {
    geocoder: false,
    homeButton: false,
    sceneModePicker: false,
    baseLayerPicker: false,
    navigationHelpButton: false,
    animation: false,
    timeline: false,
    fullscreenButton: false,
    vrButton: false,
    infoBox: false,
    shouldAnimate: true,
    contextmenu: false, //右键菜单关闭
    fxaa: true, // 不开启抗锯齿，可视域会闪烁
    control: { // 指南针和搜索
      geocoder: false,
      // compass: {
      //   top: "10px",
      //   left: "5px"
      // }
    },
    scene: {
      targetFrameRate: 30,
      resolutionScale: 1,
      scene3DOnly: true,
      globe: {
        depthTestAgainstTerrain: false, // 深度检测
      },
      contextOptions: {
        webgl: {
          alpha: true,
          depth: true,
          stencil: true,
          antialias: true,
          premultipliedAlpha: true,
          preserveDrawingBuffer: true, //开启截图功能
          failIfMajorPerformanceCaveat: true,
        },
        allowTextureFilterAnisotropic: true
      }
    },
  }
  const renderConfigStr = window.localStorage.getItem('renderConfig')
  if (renderConfigStr) {
    const renderConfig = JSON.parse(renderConfigStr)
    options.scene.targetFrameRate = renderConfig.targetFrameRate;
    options.scene.resolutionScale = renderConfig.resolutionScale;
  }
  return options
}


// 创建viewer实例
export function initViewer() {
  if (window.viewer) return
  const option = mapOptions()
  window.viewer = new mars3d.Map("CIM-container", option) // viewer 实例
  initManuallyRender(true)
}